﻿#include <QCoreApplication>
#include <QCoreApplication>
#include"opencv.hpp"
using namespace cv;
using namespace std;

#include<iostream>

#include"up.cpp"
#include"down.cpp"

int main(int argc, char *argv[])
{
  cv::Mat src = cv::imread("E:/workspace/qt/DaHeng/ng/char_right7.jpg");

  Mat updst = up(src);
  Mat downdst = down(src);

  Mat dst = src.clone();
  cvtColor(dst,dst,COLOR_BGR2GRAY);
  downdst.copyTo(dst(Rect(Point(0,src.rows/2),Point(src.cols,src.rows))));
  updst.copyTo(dst(Rect(Point(0,0),Point(src.cols,src.rows/2))));
  namedWindow("asdf",WINDOW_FREERATIO);

  imshow("asdf",dst);

  Mat dst_mask = Mat::zeros(1500,700,CV_8UC1);
  dst.copyTo(dst_mask(Rect(200,50,dst.cols,dst.rows)));
 std::vector<cv::Point> points;
  for(int x=0;x<dst_mask.rows;++x)//img.cols-
  {
    for(int y=0;y<dst_mask.cols;++y)//img.rows-
    {
      uchar a =dst_mask.at<uchar>(x,y);
       if (a>0){
        cv::Point pt;
         pt.x=y;
         pt.y=x;
//         cout<<"asd12312f";
         points.push_back(pt);
       }

      }
    }

  namedWindow("dst_mask",WINDOW_FREERATIO);

  imshow("dst_mask",dst_mask);
  cvtColor(dst_mask,dst_mask,COLOR_GRAY2BGR);
  cv::RotatedRect rect;
  cout<<points.size()<<"asdf";
  rect = fitEllipse(points);
  ellipse(dst_mask, rect,  Scalar(255, 129, 0), 2, 8);


  namedWindow("a111sdf",WINDOW_KEEPRATIO);

  imshow("as111df",dst_mask);

  waitKey(0);


}
